home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4442 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.8 KB  |  80 lines

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: void main() and other atrocities!
  5. Date: 4 Feb 1996 09:44:49 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4f2rahINNmud@keats.ugrad.cs.ubc.ca>
  8. References: <4eduaj$1aq@grouper.Exis.Net> <4epplj$egf@host-3.cyberhighway.net> <4erjn2INN38b@keats.ugrad.cs.ubc.ca> <9602021300.AA04359@dxmint.cern.ch>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <9602021300.AA04359@dxmint.cern.ch>,
  12. Dan Pop  <danpop@mail.cern.ch> wrote:
  13. >c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  14. >
  15. >>There is nothing with 'void main()'. It's not giverned by the ANSI standard,
  16. >>first of all, because that is not an ANSI definition. An ANSI definiton would
  17. >>be more like 'void main(void)'.
  18. >
  19. >'void foo()' and 'void foo(void)' are 100% equivalent as function
  20. >_definitions_ in ANSI C.  They're different only when used as function
  21. >_declarations_ (one is a prototype, the other isn't). 
  22. >
  23. >>You don't need main() to be defined has having any sort of return value unless
  24. >>you plan to "return" out of it. If you use exit(0) like me, declaring the
  25. >>function void is ok, since your function never returns.
  26. >
  27. >BULLSHIT.  Please read the FAQ before posting such nonsense.
  28. >
  29. >    AxCrnA$ cc test.c
  30. >
  31. >    void main() {exit(0);}
  32. >    .....^
  33. >    %CC-E-NEEDNONVOID, In this statement, "main(...)" has void type, but occurs
  34. >    in a context that requires a non-void result.
  35. >    at line number 2 in file DISK$L32:[DANPOP]TEST.C;3
  36.  
  37. I know that it would break a compiler that generates an incompatible linkage
  38. for functions returning int and void functions (assuming that the function you
  39. are calling does not return). But I just don't know of any that do (and it
  40. would be silly to write one that generates subroutine linkage code which breaks
  41. when a void function is called that is assumed to be int).
  42.  
  43. It's also atrocious that main() has to be treated as a special language
  44. construct, and that a call to exit() in main() (when it is the last statement)
  45. is to be identical to a return.
  46.  
  47. I don't advocate that people declare main() to return void (in fact I don't do
  48. so myself), but I don't see it as some sort of big mistake. In my own coding, I
  49. sometimes even define the argv/argc parameters even if I don't use them, just
  50. to meet the implicity prototype.
  51.  
  52. I did read the relevant section in the FAQ. It is merely concerned with the
  53. issue of eliminating compiler warnings stemming from calling exit() in main()
  54. despite a "void" declaration thereof. The issue that a void function may
  55. not be compatible with a call to an int function doesn't seem that significant,
  56. since nobody in their right mind would design a compiler that way.
  57.  
  58. In any case, I program using ANSI C only about 30% of the time. The
  59. old-fashioned function declarations are more elegant. The only truly useful
  60. thing introduced in ANSI C is the standardization of variable-length arg list
  61. handling.  It's the only thing I really miss when working with non-ANSI
  62. compilers. The other things I can handle myself: for instance, I don't need the
  63. compiler promoting arguments to their prototyped types for me. An explicit cast
  64. is more conscientious.
  65.  
  66. There is something magical about the old-style C that attracts me. I can't
  67. quite put my finger on it. I was once a very good, careful coder. I wrote neat
  68. programs in Modula 2 and similar langauges, always had carefully designed
  69. abastract data types. All my cardinal variables belonged to carefully declared
  70. and typed domains, arrays had typed ranges, etc.  It all went down hill from
  71. there!
  72.  
  73. Now I'm increasingly catching myself writing assembly code, as though I had
  74. gone full-circle. The arguments of what a main() function ought to be sound
  75. like the buzzing of flies to me.
  76.  
  77. Can someone else identify with me? :)
  78. -- 
  79.  
  80.